<!DOCTYPE html>
<#assign f = JspTaglibs["http://www.casic304.cn/f"] />
<#assign dicSelect = JspTaglibs["http://www.casic304.cn/dicSelect"]/>
<#assign SourceDept = JspTaglibs["http://www.casic304.cn/SourceDept"]/>
<html>
<head>
    <meta charset="utf-8">
    <title>失效分析信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body class="listBody">
<div class="qbdms-list">
    <div class="layui-table-view-body">
        <table id="wQbdFailureAnalysisInfoTable" lay-filter="wQbdFailureAnalysisInfoTable"></table>
    </div>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="wQbdFailureAnalysisInfoHeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <@f.a alias="sxfxxx2_xzan,sxfxxx3_xzan" css="layui-btn layui-btn-sm fillBtn" event="add">
                <span>新增</span>
            </@f.a>
            <@f.a alias="sxfxxx2_scan,sxfxxx3_scan" css="layui-btn layui-btn-sm" event="delete">
                <span>删除</span>
            </@f.a>

            <@f.a alias="dcsxfxsjxx" event="export" css="layui-btn layui-btn-sm" >
                <!-- <i class="layui-icon layui-icon-export"></i>-->
                <span>导出</span>
            </@f.a>
            <@f.a alias="sxfxxx2_dran,sxfxxx3_dran" event="import" css="layui-btn layui-btn-sm" >
                <!--<i class="layui-icon layui-icon-download-circle"></i>-->
                <span>导入</span>
            </@f.a>

            <@f.a alias="sxfxxx2_sban,sxfxxx3_sban" event="report" css="layui-btn layui-btn-sm" >
                <span>上报</span>
            </@f.a>
            <a class="layui-btn layui-btn-sm" lay-event="listStyle">
                <span>配置列</span>
            </a>
        </div>
        <form class="layui-form" action="" lay-filter="wQbdFailureAnalysisInfoQueryForm">
            <div class="layui-form-body selch">
                <div class="table-top-filter layui-row">
                    <@SourceDept.dept css="layui-input filter-value "/>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">元器件名称</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input filter-value" name="Q_componentsName_SL"
                                   placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">失效分析单位</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input filter-value" name="Q_unitOfAnalysis_SL"
                                   placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">型号规格</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input filter-value" name="Q_modelSpec_SL"
                                   placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">所属型号代号</label>
                        <div class="layui-input-block">
                            <select name="Q_modelCode_S" class="xhdh layui-input filter-value" lay-filter="xh"
                                    lay-verify="required" lay-search=""></select>
                        </div>
                    </div>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">失效开始时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input start_time1 filter-value"
                                   name="Q_beginExpirationTime_DL" readonly
                                   placeholder="请输入"/>
                        </div>
                    </div>
                    <div class="qbdms-listForm">
                        <label class="layui-form-label">失效结束时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input end_time1 filter-value" name="Q_endExpirationTime_DE"
                                   readonly   placeholder="请输入"/></div>
                    </div>
                </div>
                <div class="selchBtn">
                    <a class="layui-btn layui-btn-sm fillBtn" lay-event="query">
                        <span>查询</span>
                    </a>
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-sm" lay-event="clears"
                                style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont  data-iconcommon_refresh"></i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm screenParent" lay-event="screen"
                                style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_downarrow screen"></i>
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="wQbdFailureAnalysisInfoRightToolsBar">


    {{# if('${currentUserId}'==d.createBy && d.allowEdit){}}
    <@f.a alias="sxfxxx2_xgan,sxfxxx3_xgan" event="edit" css="RightBtn">编辑</@f.a>
    {{#  } }}
    <a class="RightBtn" lay-event="particulars">详情</a>

    {{# if('${currentUserId}'==d.createBy && (d.reportStatus==4||d.reportStatus==12)){}}
    <@f.a alias="sxfxxx2_scan,sxfxxx3_scan" event="del" css="RightBtn">删除</@f.a>
    {{#  } }}

</script>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'setter', 'form', 'common', 'publicMethods', 'jquery', 'layer','propsHandle'], function () {
        var table = layui.table;
        var setter = layui.setter;
        var form = layui.form;
        var common = layui.common;
        var publicMethods = layui.publicMethods;
        var $ = layui.jquery;
        var layer = layui.layer;
        var propsHandle = layui.propsHandle;
        var defProps = {
                //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
                viewMould: 'moulds/', // 组件模块 存放文件 *****
                selectorBtn: '.selectorBtn'
            },
            temQuery = new propsHandle();  // 实例化模板功能部分
        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });
        common.tableSort('wQbdFailureAnalysisInfoTable');
        var tableH = publicMethods.tabHeight();
        var cols = '${cols}';
        //第一个实例
        window.tableInstace = function (tcols) {
            if (tcols) {
                cols = tcols;
            }
            if (cols) {
                cols = JSON.parse(cols, function (k, v) {
                    if (v.indexOf && v.indexOf('function') > -1) {
                        return eval("(function(){return " + v + " })()")
                    }
                    return v;
                })
            }

            window.tableInstace.initCols = [ //初始化的表头， 这里替换成自己的初始化表头json
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}

                <#if syslev=='GROUPLEVEL' >
                , {field: 'filldeptHospital', title: '数据来源单位', minWidth: '200'}
                </#if>
                <#if syslev!='GROUPLEVEL' >
                , {field: 'filldept', title: '数据来源单位', minWidth: '200'}
                </#if>
                , {field: 'unitOfAnalysis', title: '分析单位', sorf:false, sortname: 'unit_of_analysis', minWidth: '150'}
                , {
                    field: 'expirationTime',
                    title: '失效时间',
                    sorf:false,
                    sortname: 'expiration_time',minWidth:'120',
                    templet: function (d) {
                        return publicMethods.timeData(d.expirationTime);
                    }
                }
                , {field: 'componentsName', title: '元器件名称', sorf:false, sortname: 'components_name', minWidth: '100'}
                , {field: 'modelSpec', title: '型号规格', sorf:false, sortname: 'model_spec', minWidth: '150'}
                , {field: 'batch', title: '批次', sorf:false, sortname: 'batch', minWidth: '100'}
                , {field: 'modelCode', title: '型号代号', sorf:false, sortname: 'model_code', minWidth: '150'}

                , {field: 'failAnalysisReportNo', title: '失效分析报告编号', hide:true,   minWidth: '150'}
                , {field: 'productionUnit', title: '生产单位', hide:true,   minWidth: '150'}
                , {field: 'qualityLevel', title: '质量等级', hide:true,   minWidth: '150'}
                , {field: 'failNums', title: '失效数量', hide:true, align:'right', minWidth: '150',
                    templet:function(d){
                        return common.redNum(d.failNums);
                    }
                }
                , {field: 'modelCode', title: '所属整机代号', hide:true,   minWidth: '150'}
                , {field: 'failStage', title: '失效发生阶段', hide:true,   minWidth: '150'}
                , {field: 'failMode', title: '失效模式', hide:true,   minWidth: '150'}
                , {field: 'requester', title: '委托单位', hide:true,   minWidth: '150'}
                , {field: 'failPlace', title: '失效地点', hide:true,   minWidth: '150'}
                , {field: 'analysisConclusion', title: '分析结论', hide:true,   minWidth: '150'}
                , {field: 'reasonForFail', title: '失效原因', hide:true,   minWidth: '150'}
                , {field: 'failPhenomenon', title: '故障现象', hide:true,   minWidth: '150'}

                <#if syslev!='GROUPLEVEL' >
                , {
                    field: 'reportStatusStr', title: '上报状态', minWidth: '160',
                    templet: function (d) {
                        return common.stateType(d);
                    }
                }
                </#if>
                , {
                    fixed: 'right',
                    title: '管理',
                    toolbar: '#wQbdFailureAnalysisInfoRightToolsBar', minWidth: '150'
                }
            ];

            window.tableInstace.tRender = table.render({
                elem: '#wQbdFailureAnalysisInfoTable'
                , height: tableH
                , page: publicMethods.pageFun() //开启分页
                , limit: 20
                , url: '${ctx}/qbdms/wQbdFailureAnalysisInfo/list'
                , toolbar: '#wQbdFailureAnalysisInfoHeaderToolsBar'
                , method: 'post'
                , defaultToolbar: ['']
                , autoSort: false //是否排序
                , cols: [cols ? cols : window.tableInstace.initCols]
                , done: function () {
                    common.tableSelectCon('.ccpui-enterSel .layui-form input', 'a[lay-event=query]', '.ccpui-enterSel');
                    table.resize();
                }
            });
        };
        window.tableInstace(cols);

        dateReflash()


        function dateReflash() {
            publicMethods.reflashDate({startName: '.start_time1', endName: '.end_time1'});

            var xhdh = eval('${wQbdXhdhs}'); //型号代号
            var initXHDH = function (optionObj, item) {
                optionObj.text = item.fModelcode;
                optionObj.value = item.fModelcode;
                optionObj.setAttribute("xhdh", item.fModelname);
            };
            common.initDicData("Q_modelCode_S", xhdh, "", initXHDH);
        }

        function reflashQuery(isClear) {
            common.tableConditionRender("wQbdFailureAnalysisInfoTable", "wQbdFailureAnalysisInfoQueryForm", {where: {}}, isClear, false, 20);
        }

        table.on('toolbar(wQbdFailureAnalysisInfoTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            var layerH=publicMethods.layHeight('.listBody');
            switch (obj.event) {
                case 'add':
                    window.location.href = "${ctx}/qbdms/wQbdFailureAnalysisInfo/view/add";
                    break;
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array += data[i].id + ",";
                    }
                    delFun(data, array);
                    break;
                case "report":
                    var ids = "";
                    for (var i = 0; i < data.length; i++) {
                        ids += data[i].id + ",";
                    }
                    //业务表名,勾选数据主键,流程key,table标签lay-filter属性值,form标签lay-filter属性值,是否允许重复上报,页面所在包名,流程定义id
                    common.report("w_qbd_failure_analysis_info", ids, "plantToHospital"
                        , "wQbdFailureAnalysisInfoTable", "wQbdFailureAnalysisInfoQueryForm", false, "wQbdFailureAnalysisInfo", "plantToHospital:1:72d05d40362249118c5453aa60c6da90");
                    dateReflash();
                    break;
                case 'export':

                function open(url, param) {
                    var curUrl = url;
                    layer.open({
                        type: 2,
                        area: ['700px', '520px'],
                        title: ['自定义导出', 'font-size:14px;'],
                        content: serverPath.qbdmsPath + '/qbdms/wQbdFailureAnalysisInfo/view/export',
                        btnAlign: 'c',
                        skin: 'qbdms-layerFormBtn',
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            url = curUrl;
                            var iframeWin = window["layui-layer-iframe" + index];
                            var data = iframeWin.getData();
                            if (data) {
                                url = url + "?data=" + JSON.stringify(data) + param;
                                window.location.href = encodeURI(url)
                            }
                        }
                    });
                }

                    if (data.length == 0) {
                        layer.confirm(publicMethods.confirmStyle('还没有选择，是否导出全部？'), {
                            title: false,
                            skin: 'confirm-class'
                        }, function (index) {
                            layer.close(index);
                            var url = '${ctx}/qbdms/wQbdFailureAnalysisInfo/exportData';
                            var param = "";
                            $("form[lay-filter='wQbdFailureAnalysisInfoQueryForm']").find(".filter-value").each(function (i, value) {
                                param += "&" + this.name + "=" + this.value
                            });
                            open(url, param);
                        });
                    } else {
                        layer.confirm(publicMethods.confirmStyle('确定导出吗？'), {
                            title: false,
                            skin: 'confirm-class'
                        }, function (index) {
                            layer.close(index);
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].id);
                            }
                            var url = '${ctx}/qbdms/wQbdFailureAnalysisInfo/exportData';
                            open(url, "&id=" + ids);
                        });
                    }
                    break;
                case "import":
                    common.importInit('wQbdFailureAnalysisInfoTable',"/qbdms/wQbdFailureAnalysisInfo/importData",true,"/importTemplates/失效分析信息.xlsx");
                    dateReflash();
                    break;
                case "query":
                    reflashQuery(false);
                    dateReflash();
                    break;
                case "clears":
                    reflashQuery(true);
                    dateReflash();
                    break;
                case "screen":
                    common.initScreenTop('wQbdFailureAnalysisInfoTable');
                    dateReflash();
                    form.render();
                    break;
                case "listStyle":
                    layer.open({
                        type: 2,
                        area: ['80%', layerH],
                        skin: 'qbdms-layerFormBtn',
                        title: ['新增列表样式', 'font-size:14px;'],
                        content: '${ctx}/qbdms/wCustomColumns/view/list',
                        success:function (layero, index) {
                            publicMethods.tipsAuto(layero.find('.layui-layer-setwin'),'点击这里关闭弹框哦',2000)
                        }
                    });
                    break;
            }
            ;
        });

        table.on('tool(wQbdFailureAnalysisInfoTable)', function (obj) {
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
            switch (layEvent) {
                case "edit":

                    window.location.href = '${ctx}/qbdms/wQbdFailureAnalysisInfo/view/add?id=' + data.id;
                    break;
                case "particulars":

                    window.location.href = '${ctx}/qbdms/wQbdFailureAnalysisInfo/view/particulars?id=' + data.id;
                    break;
                case "del":
                    delFun(data, data.id);
                    break;
            }
        });

        function delFun(data, id) {
            if (data.length === 0) {
                layer.msg('请先选择一行数据!',{title: false,skin: 'confirm-class'});
            } else {
                layer.confirm(publicMethods.confirmStyle('确定删除当前数据吗?'), {
                    title: false,
                    skin: 'confirm-class'
                }, function (index) {
                    layer.close(index);
                    $.ajax({
                        url:  "${ctx}/qbdms/wQbdFailureAnalysisInfo/del",
                        type: "post",
                        data: {id: id},
                        dataType: 'json',
                        success: function (data) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            reflashQuery(true);
                            dateReflash();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            reflashQuery(true);
                            dateReflash();
                        }
                    })
                })
            }
        }

        window.Initialization = function () {
            reflashQuery(false);
            dateReflash();
        };
        /*刷新时间控件*/
        //list页面初始化展开按钮tips展示（展开按钮类名）
        publicMethods.tipsAuto('.screen')
        //筛选条件初始化（页面表格的Id，是否初始化（true、false））
        common.initScreenTop('wQbdFailureAnalysisInfoTable', true);
        dateReflash();
        common.tableSort("wQbdFailureAnalysisInfoTable", {show: window.Initialization});
    });
</script>
</body>
</html>